//搜索框
$(function(){
	$('.shop').addClass('curr').siblings().removeClass('curr');
	$("#shop").css("display", "block");
	$('#goods').css("display", "none");
})
//品牌查询店铺
 
	var shopId = getvl("shopId");
	var shopName = getvl1("shopName");
	//if(shopId != '') {
		loadMyEssay('', '', '', '', '', '', '', '', shopId,shopName);
//	}
 

//商圈
TradeArea();
//分类
sortType();
//属性
propertyType();

var currentPage = 1;
var tradeAreaId = '';
var sortTypeId = '';
var propertyTypeId = '';
var tradeNumber = '',
	isChange = '';
var sort = ''; //排序
//价格区间
var betweenMoney = '';

var goodsType = ''; //商品类型
//列表

function loadMyEssay(tradeAreaId, sortTypeId, propertyTypeId, tradeNumber, goodsType, isChange, sort, betweenMoney, shopId,shopName) {
	$(document).ready(function() {
		init(currentPage);
	});

	function init(pageNo) {
		$("#shopList").html("");
		$.ajax({
			url: urlcore + "/api/tradeArea/selectTradeGoodsList?tradeAreaId=" + tradeAreaId + "&sortTypeId=" + sortTypeId + "&propertyTypeId=" + propertyTypeId + "&tradeNumber=" + tradeNumber + "&goodsType=" + goodsType + "&isChange=" + isChange + "&sort=" + sort + "&betweenMoney=" + betweenMoney + "&shopId=" + shopId + "&shopName="+shopName+"&size=" + 32 + "&current=" + pageNo,
			type: "get",
			dataType: 'json',
			async: false,
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					 $('#shopName').val(shopName);
					$.each(data.data.list, function(i, n) {

						var headImg = n.headImg==null?'http://app.jiagangwangluo.com/api//ATTACHMENT/cab06117-6607-401a-843d-5ac103323fb6/sqz.png':n.headImg;
						headImg=isHasImg(headImg);
						var storeName=n.storeName==null?'暂无':n.storeName;
						var province=n.province==null?'暂无':n.province;
						var city=n.city==null?'暂无':n.city;
						var address=n.address==null?'暂无':n.address;
						var monthNew=n.monthNew==null?0:n.monthNew;
                        var saleMoney=n.saleMoney==null?0:n.saleMoney;
						var thislist =
							'<dl>' +
							'<a target="_blank" href="10.1.0dianpu_detail.html?id='+n.id+'">' +
							'<dt>' +
							'<img class="searchShopImg" src="' + headImg + '" />' +
							'</dt>' +
							'<dd>' +
							'<h5>' +
							'<img src="images/dianpu.png" />' +
							storeName +
							'</h5>' +
							'<p>' + province + '-' + city + '-' + address + '</p>' +
							'<div class="clearfix index_dianpu_xin">' +
							'<span class="fl">上新： <em>' + monthNew + '</em></span>' +
							'<span class="fr">销售额：<em>' + saleMoney + '</em></span>' +
							'</div>' +
							'</dd>' +
							'</a>' +
							'</dl>';

						$('#shopList').append(thislist);
					});
					
					 //固定宽高
					$(function(){
						var imgList1 = document.getElementsByClassName("searchShopImg");  
					    var w=290;
					    var h=280;
					    for(var i=0;i<imgList1.length;i++){
					        if(imgList1[i].width>w || imgList1[i].height>h){  
					            imgList1[i].width = w;  
					            imgList1[i].heigth = h;  
					        }  
					    }  
					})

					$("#pager").pager({
						pagenumber: pageNo,
						pagecount: data.data.pages,
						totalcount: data.data.total,
						buttonClickCallback: PageClick
					});

				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					//alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}

				} else {
					if(data.msg != '空数据') {
						layer.alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}

			},
			error: function() {
				layer.alert("error");
			}
		});
	}
	PageClick = function(pageclickednumber) {
		init(pageclickednumber);
	}
}

//按区域查询
function searchByTradeArea(tradeAreaId) {
	loadMyEssay(tradeAreaId, '', '', '', '', '', '', '', '','');
}

//按分类查询
function searchBySortType(sortTypeId) {
	$.ajax({
		url: urlcore + "/api/sortType/selectOne?id=" + sortTypeId,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				$("#breadcrumbName").text(data.data.sortName);
			}
		},
		error: function() {
			layer.alert("error");
		}
	});

	loadMyEssay('', sortTypeId, '', '', '', '', '', '', '','');
}

//按属性查询
function searchByPropertyType(propertyTypeId) {
	loadMyEssay('', '', propertyTypeId, '', '', '', '', '', '','');
}

//搜索 一件起批   热销商品   支持包换
function selectGoods(tradeNumber, goodsType, isReturnedOfSevenDays) {

	loadMyEssay('', '', '', tradeNumber, goodsType, isReturnedOfSevenDays, '', '', '','');
}
//按时间,单价,收藏量,销售量排序
function selectGoodsOrderBySort(sort) {
	loadMyEssay('', '', '', '', '', '', sort, '', '','');
}
//按价格区间以及起批量查询 
function selectGoodsByMoneyOrTradeNumber() {
	var minPprice = $("#min_price").val().trim();
	var maxPrice = $("#max_price").val().trim();
	var betweenMoney = '';
	if(minPprice != '' && minPprice != null && maxPrice != '' && maxPrice != null) {
		betweenMoney = minPprice + "-" + maxPrice;
	}
	var retailPum = $("#retail_num").val().trim();

	loadMyEssay('', '', '', retailPum, '', '', '', betweenMoney, '','');
}

 